package org.metasketch.editor.toolbox;

import java.util.List;

import org.metasketch.editor.diagrams.DiagramManager;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;

public class DiagramTypeCreator extends VBox implements
		EventHandler<ActionEvent> {

	DiagramManager diagramManager;

	public DiagramTypeCreator(DiagramManager manager) {

		setPrefWidth(200);
		setMaxWidth(200);
		setMinWidth(200);
		
		this.diagramManager = manager;

		List<String> names = manager.getNames();
		for (String name : names) {
			createButton(name);
		}

	}

	private void createButton(String name) {
		Button button = new Button(name);
		button.setOnAction(this);

		
		button.setMaxWidth(200);
		button.setMinWidth(200);
		button.setPrefWidth(200);
		
		getChildren().add(button);

	}

	@Override
	public void handle(ActionEvent arg0) {

		Button button = (Button) arg0.getSource();

		String name = button.getText();

		diagramManager.createNewDiagram(name);
	}

}
